package parttern.responsibility;

public abstract class AbsLog {

    public static final int VERBOSE = 1;
    public static final int DEBUG = 2;
    public static final int INFO = 3;

    protected int level;

    protected AbsLog nextLog;

    public void setNextLog(AbsLog nextLog) {
        this.nextLog = nextLog;
    }

    public void logMsg(int level, String msg) {
        if (this.level <= level) {
            write(msg);
        }
        if (null != nextLog) {
            nextLog.logMsg(level, msg);
        }
    }

    public abstract void write(String msg);


    ///test
    public static void main(String[] args) {
        AbsLog logV = new LogV(AbsLog.VERBOSE);
        AbsLog logD = new LogD(AbsLog.DEBUG);
        AbsLog logI = new LogI(AbsLog.INFO);
        logI.setNextLog(logD);
        logD.setNextLog(logV);

        logI.logMsg(AbsLog.VERBOSE, "vvv");
        logI.logMsg(AbsLog.DEBUG, "ddd");
        logI.logMsg(AbsLog.INFO, "iii");
    }
}
